package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    //加载系别列表
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam(value = "pageNum" ,required = false) Integer pageNum,
                                         @RequestParam(value = "pageSize" ,required = false) Integer pageSize,
                                          SupplierVO supplierVO){

              PageVO pageVO =
                      supplierService.findSupplierList(pageNum,pageSize,supplierVO);
        return ResponseBean.success(pageVO);
    }
    //添加
    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return  ResponseBean.success();
    }

    //编辑 用于回显数据

    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
       SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    //更新数据、
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody @Validated SupplierVO supplierVO ,
                               @PathVariable Long id){
        supplierService.update(id , supplierVO);
        return ResponseBean.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }
}
